package arrAndstr;

/*
    122. 买卖股票的最佳时机 II
 */
public class T122 {
    public static void main(String[] args) {
        int[] array = new int[]{7,6,4,3,1};

        System.out.println(maxProfit(array));
    }

    public static int maxProfit(int[] prices) {
        // 买涨不买跌
        int len = prices.length;
        if(len == 1) {
            return 0;
        }

        int result = 0;
        for(int i=0; i<len-1; i++) {
            if(prices[i+1] > prices[i]) {
                result += prices[i+1] - prices[i];
            }
        }
        return result;
    }
}
